package com.gjy.test.other;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.text.SimpleDateFormat;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2022-12-06 17:57:14
 */
public class T3 {

    private static final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

    public static void main(String[] args) {

        /*List<Vo> collect = Stream.of(new Vo("2022-12-19"), new Vo("2021-12-19"),
                        new Vo("2020-12-19"), new Vo("2020-12-19"),
                        new Vo("2020-12-19"), new Vo("2020-12-23"), new Vo("2020-12-29"))
                .sorted(Comparator.comparingLong(value -> {
                    try {
                        return format.parse(value.getDate()).getTime();
                    } catch (ParseException e) {
                        throw new RuntimeException(e);
                    }
                }))
                .collect(Collectors.toList());*/
        List<Vo> collect = Stream.of(new Vo("2022-12-19"), new Vo("2021-12-19"),
                        new Vo("2020-12-19"), new Vo("2020-12-19"),
                        new Vo("2020-12-19"), new Vo("2020-12-23"), new Vo("2020-12-29"))
                .sorted(Comparator.comparing(Vo::getDate).reversed())
                .collect(Collectors.toList());
        System.out.println(collect);
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    private static class Vo {
        private String date;
    }
}
